package com.zwy.space.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zwy.space.domain.Images;
import com.zwy.space.queryVo.ResourceVo;
import com.zwy.space.service.ImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
@RequestMapping("/image")
public class ImageController {

    @Autowired
    private ImageService imageService;

    @RequestMapping
    public String findAllImages(Model model, @RequestParam(defaultValue = "1",value = "pageNum")Integer pageNum){
           PageHelper.startPage(pageNum,10);
           List<Images> imagesList=imageService.findAllImages();
        PageInfo<Images> pageInfo = new PageInfo<>(imagesList);
        model.addAttribute("pageInfo",pageInfo);
        return "images";
    }

    @RequestMapping("/{timeId}")
    public String findImagesByTime(Model model, @RequestParam(defaultValue = "1",value = "pageNum")Integer pageNum, @PathVariable int timeId){
        PageHelper.startPage(pageNum,10);
        List<Images> imagesList=imageService.findImagesByTime(timeId);
        PageInfo<Images> pageInfo = new PageInfo<>(imagesList);
        model.addAttribute("pageInfo",pageInfo);
        return "images";
    }

}
